{% extends "base.html" %}

{% block content %}
	<h1>Books pending review</h1>
	
	{% if books %}
		<table>
			<thead>
				<th>Title &amp; Author</th>
                <th>Assigned To</th>
				<th class="align-right">Action</th>
			</thead>
			<tbody>
				{% for book in books %}
					<tr>
						<td class="title">
							{{ book.title }} by {{ book.list_authors }}
						</td>
                        <td>
                            {% if book.reviewed_by == request.user%}
                                <span class="highlight">Me</span>
                            {% elif book.reviewed_by %}
                                {{ book.reviewed_by.get_full_name|default:book.reviewed_by.username }}
                            {% else %}
                                -
                            {% endif %}
                        </td>
						<td class="align-right">
							<a href="{% url 'review-book' book.pk %}">Review</a>
						</td>
					</tr>
				{% endfor %}
			</tbody>
		</table>
	{% else %}
		<p>There are no books waiting to be reviewed.  Good job!</p>
	{% endif %}
	
	<h2>Request a new review</h2>
<form method="post">
	{% csrf_token %}

	{% if form.non_field_errors %}
		<div class="non-field-errors">
			{% for error in form.non_field_errors %}
				<span>{{ error }}</span>
			{% endfor %}
		</div>
	{% endif %}

	<label>{{ form.title.label }}</label>
	{{ form.title }}
	{{ form.title.help_text }}

	{% if form.title.errors %}
		<div class="form-error">
			{% for error in form.title.errors %}
				<span>{{ error }}</span>
			{% endfor %}
		</div>
	{% endif %}

	<label>{{ form.authors.label }}</label>
	{{ form.authors }}
	{% if form.authors.errors %}
		<div class="form-error">
			{% for error in form.authors.errors %}
				<span>{{ error }}</span>
			{% endfor %}
		</div>
	{% endif %}

	<p>Can't find the author you're looking for? <a href="{% url 'add-author' %}">Create a New Author</a></p>

    <label>Assigned To</label>
    {{ form.reviewed_by }}
    {% if form.reviewed_by.errors %}
        <div class="form-error">
            {% for error in form.reviewed_by.errors %}
                <span>{{ error }}</span>
            {% endfor %}
        </div>
    {% endif %}

	<input type="submit" value="Add Book">
</form>

{% endblock %}
